﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
            <div class="demo-login-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">资源</label>
                    <div class="layui-input-block">
                        <select name="interest" id="ProcessDetailName" lay-filter="aihao">
                            <option value="0">请选择</option>

                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">资源单位</label>
                    <div class="layui-input-block">
                        <select name="interest" lay-filter="aihao" id="ProcessDetailUnits">
                            <option value=""></option>
                            <option value="0">个/台</option>
                            <option value="1">次</option>
                            <option value="2">克</option>
                            <option value="3">千克</option>
                            <option value="4">小时</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">资源用量</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" id="ProcessDetailDosage" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">单位成本</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" id="UnitsPrice" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">摘要</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" id="Summary" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select name="interest" lay-filter="aihao" id="ProcessDetailState">
                            <option value=true>有效</option>
                            <option value=false>无效</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-primary layui-border" onclick="layer.close(index1)">返回</button>
                    <button type="button" class="layui-btn layui-bg-blue" onclick="ProcessDetailAdd()">确定</button>
                </div>
            </div>
        </div>
    </form>

    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.20/dist/layui.js"></script>
    <script>
        layui.use(['form', 'laydate', 'util'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
        });

    </script>

</body>
</html>
<script>

    var id = localStorage.getItem("workid");
    var ProcessNumber = localStorage.getItem("ProcessNumber");

    ResouresList()



    function ResouresList() {
        $.get({
            url: '@ViewBag.RBACWrite' + "/api/Process/ResourcesList?workCenterCode=" + id,
            async: false,
            dataType: "json",
            contentType: "application/json",
            success: res => {
                $.each(res.data, function () {
                    $("#ProcessDetailName").append(`<option value="${this.resourceCode}">${this.resourceName}</option>`)
                })
            }
        })

    }
    //工艺资源新增
    function ProcessDetailAdd() {
        console.log(ProcessNumber);
        var data = {
            ProcessNumber: ProcessNumber,
            ProcessId: 0,
            ProcessDetailName: $("#ProcessDetailName").val(),
            ProcessDetailUnits: $("#ProcessDetailUnits").val(),
            ProcessDetailDosage: $("#ProcessDetailDosage").val(),
            UnitsPrice: $("#UnitsPrice").val(),
            Summary: $("#Summary").val(),
            ProcessDetailState: $("#ProcessDetailState").val()=='true',
        }
        $.post({
            url: '@ViewBag.RBACWrite' + "/api/Process/ProcessDetailAdd",
            data: JSON.stringify(data),
            async:false,
            dataType:"Json",
            contentType: "application/json",
            success: res => {
                if (res.code == 1) {
                    layer.alert("新增成功");
                    return;
                }
                else {
                    layer.alert("新增失败");
                    return;
                }
            }
        })
    }
</script>